<?php

namespace app\api\controller;

use app\admin\model\spider\Spider as spiderModel;
use app\admin\model\spider\SpiderPrices as spiderPricesModel;
use app\common\controller\Api;

/**
 * 示例接口
 */
class Demo extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    public function test()
    {
        die;
        $keywords = "X Drake One Piece";
        $keywords = urlencode($keywords);
        //   /shop/images/teepublic/One Piece - Thousand sunny pirates ship T-Shirt--67c91643d3495.jpg
        // https://res.cloudinary.com/teepublic/image/private/s--R6IzkwvU--/t_Resized Artwork/c_crop,x_10,y_10/c_fit,h_586/c_crop,g_north_west,h_586,w_460,x_0,y_0/g_north_west,u_upload:v1636652761:production:blanks:kqwlxpcn9aizlzfxaa6i,x_-400,y_-306/b_rgb:eeeeee/c_limit,f_auto,h_630,q_auto:good:420,w_630/v1652984938/production/designs/30526344_0.jpg_____https://res.cloudinary.com/teepublic/image/private/s--IWWdnRwv--/b_rgb:39383d,t_Heather Preview/t_watermark_lock/c_limit,f_auto,h_630,q_auto:good:420,w_630/v1652984938/production/designs/30526344_0.jpg
        $params = [
//            "get_url" => 'https://www.teepublic.com/hoodie/69200335-kizaru-t-shirt',
//            "get_url" => 'https://www.teepublic.com/hoodie/34817433-the-drake-equation-alien-life-in-the-universe',
//            "shop_uniqid" => 'FD9haMcQsEqBw4AKT17b0oGmLZVziN5U',

            "get_url" => 'https://www.teepublic.com/hoodie?canvas_subclass=classic-hoodie&gender=unisex&query=' . $keywords,

//            "get_url" => 'https://www.teepublic.com/t-shirts?query=one+piece&query_concierge_eligible=true',  //固定关键字：one piece

            "task_id" => 11,
        ];

        $ret = \app\common\services\Task::spider($params);
        dump($ret);
//
        echo date('Y-m-d H:i:s');die;
//        $ret = \spider\Spider::spider($params);
//        if (!empty($ret['shopInfo'])) {
//            $spiderRow = spiderModel::where(['shop_uniqid' => $ret['shopInfo']['shop_uniqid']])->find();
//            $spiderRow->page_title = $ret['shopInfo']['page_title'];
//            $spiderRow->meta_description = $ret['shopInfo']['meta_description'];
//            $spiderRow->store_url = $ret['shopInfo']['store_url'];
//            $spiderRow->shop_description = $ret['shopInfo']['shop_description'];
//            $spiderRow->save();
//
//            (new spiderPricesModel)->saveAll($ret['list']);
//        }
//        dump($ret);
    }

}
